import {routerFilter} from '../../utils/routerFilter';
import eycService from "../../js/eycService";
import Toast from '@vant/weapp/toast/toast';
import util from '../../utils/util';
routerFilter({

  /**
   * 页面的初始数据
   */
  data: {
    vehicleConds: [
      { name: '优秀' ,code:1.05},
      { name: '良好',code:1},
      { name: '一般',code:0.95}
    ],
    collisions: [
      { name: '无' ,code:1},
      { name: '做过油漆',code:0.95},
      { name: '小碰擦',code:0.85},
      { name: '中大事故',code:0.7},
    ],
    colors: [
      { name: '黑色' ,code:0},
      { name: '白色',code:0},
      { name: '银色',code:0},
      { name: '其他',code:-300}
    ],
    option1: [
      { name: '有' ,code:1},
      { name: '无',code:0}
    ],
    option2: [
      { name: '是',code:1},
      { name: '否',code:0}
    ],
    option3: [
      { name: '自动' },
      { name: '手动'}
    ],
    option4: [
      { name: '国六' },
      { name: '国四国五'},
      { name: '国三及以下'}
    ],
    option5: [
      { name: '1.2-3.0' },
      { name: '大于3.0'},
      { name: '小于1.2'}
    ],
    producers: [
      { name: '国产品牌' ,code:0.9},
      { name: '合资品牌',code:0.95},
      { name: '进口品牌',code:1}
    ]

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  packup(event){
   let isFold  =!event.target.dataset.isFold;
   this.setData({isFold:isFold});
  },
  selectVehicle(event) {
    let that = this;
    wx.navigateTo({
      url: '/pages/vehicle/vehicleFileItems',
      events: {
        // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
        acceptVehicleFileFromItemsPage: function (vehicleFile) {
          that.setData({vehicleFile:vehicleFile});
        }
      },
      success: function (res) {
        // 通过eventChannel向被打开页面传送数据
        // res.eventChannel.emit('acceptDataFromOpenerPage', { data: 'test' })
      }
    })

  },
  evaluatingPrice(event){
    let data=this.data;
    let vehicle=data.vehicleFile;
    if(!vehicle.plateNum){
      Toast('请选择车辆');
      return;
    }
    if(!vehicle.purchasePrice){
      Toast('请输入购买价格');
      return;
    }
    if(!vehicle.totalMileage){
      Toast('请输入行车里程');
      return;
    }
    if(!vehicle.vehicleCond){
      Toast('请选择车况');
      return;
    }
    if(!vehicle.collision){
      Toast('请选择碰撞情况');
      return;
    }
    vehicle.avAmount= eycService.evaluatingPrice(vehicle);
    this.setData(data);
    let items=[];
    if(vehicle.color){
      items.push({parmId:'颜色',value:vehicle.color});
    }
    if(vehicle.skylight){
      items.push({parmId:'天窗',value:vehicle.skylight});
    }
    if(vehicle.leatherSeat){
      items.push({parmId:'真皮座椅',value:vehicle.leatherSeat});
    }
    if(vehicle.isRepair){
      items.push({parmId:'包养是否4S店',value:vehicle.isRepair});
    }
    if(vehicle.param1){
      items.push({parmId:'变速箱',value:vehicle.param1});
    }
    if(vehicle.param2){
      items.push({parmId:'排放',value:vehicle.param2});
    }
    if(vehicle.param3){
      items.push({parmId:'排量',value:vehicle.param3});
    }
    if(vehicle.producer){
      items.push({parmId:'国别',value:vehicle.producer});
    }
    vehicle.items=items;
    util.promise('/insertEycVehicleAv',vehicle).then(function (res) {
      if(res.data){
        Toast('估值完成~~');
      }
    });
  },
  drService(event){
    let that = this;
    wx.navigateTo({
      url: '/pages/vehicle/vehicleAvAddr',
      events: {
        // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
        acceptVehicleFileFromItemsPage: function (vehicleFile) {
          that.setData({vehicleFile:vehicleFile});
        }
      },
      success: function (res) {
        // 通过eventChannel向被打开页面传送数据
        // res.eventChannel.emit('acceptDataFromOpenerPage', { data: 'test' })
      }
    })
  }
});